/**
 * 
 */
package metalink;

import java.sql.ResultSet;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Reaper
 * 
 */
import model.ForgotPasswordMo;
import myutil.Connect;
import vo.LoginInfoVo;
public class CheckUsername extends ActionSupport{
	String login_id="",site="";
	long number;
	public String execute() {
		ForgotPasswordMo mo=new ForgotPasswordMo();
		try {
			if(mo.verifyLoginIdSite(login_id, site)==true)
			{
				number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
				checkrandom();
				Connect c=new Connect();
				c.dml("update login_info set cid=" + number + " where login_id='"+login_id+"'");
				SendMail1 s=new SendMail1();
				s.to=login_id;
				s.message="<a href=\"http://192.16.11.96:8080/CampusMetalink/confirmation.action?site="+site+"&cid="+number+"\">Click Here </a> to reset your password";
				s.main();
				setLogin_id(login_id);
				setSite(site);
				System.out.println("maill sent to "+login_id+"");
				return SUCCESS;
			}
			else
			{
				addActionError("invalid login_id or site_id");
				return ERROR;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	public void checkrandom() throws Exception {
		Connect c=new Connect();
		ResultSet rs=c.getResult("select * from login_info where cid="+number+"");
		if(rs.next()){
			number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
			checkrandom();
		}
		else{
			return ;
		}
	}
	public String getLogin_id() {
		return login_id;
	}
	public void setLogin_id(String login_id) {
		this.login_id = login_id;
	}
	public String getSite() {
		return site;
	}
	public void setSite(String site) {
		this.site = site;
	}
	
}
